package com.smarthealthcare.devicetype.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smarthealthcare.common.annotation.Log;
import com.smarthealthcare.common.core.controller.BaseController;
import com.smarthealthcare.common.core.domain.AjaxResult;
import com.smarthealthcare.common.enums.BusinessType;
import com.smarthealthcare.devicetype.domain.Devicetype;
import com.smarthealthcare.devicetype.service.IDevicetypeService;
import com.smarthealthcare.common.utils.poi.ExcelUtil;
import com.smarthealthcare.common.core.page.TableDataInfo;

/**
 * 设备类型表Controller
 * 
 * @author YF
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/device/devicetype/devicetype")
public class DevicetypeController extends BaseController
{
    @Autowired
    private IDevicetypeService devicetypeService;

    /**
     * 查询设备类型表列表
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:list')")
    @GetMapping("/list")
    public TableDataInfo list(Devicetype devicetype)
    {
        startPage();
        List<Devicetype> list = devicetypeService.selectDevicetypeList(devicetype);
        return getDataTable(list);
    }

    /**
     * 导出设备类型表列表
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:export')")
    @Log(title = "设备类型表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Devicetype devicetype)
    {
        List<Devicetype> list = devicetypeService.selectDevicetypeList(devicetype);
        ExcelUtil<Devicetype> util = new ExcelUtil<Devicetype>(Devicetype.class);
        util.exportExcel(response, list, "设备类型表数据");
    }

    /**
     * 获取设备类型表详细信息
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devicetypeService.selectDevicetypeById(id));
    }

    /**
     * 新增设备类型表
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:add')")
    @Log(title = "设备类型表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Devicetype devicetype)
    {
        return toAjax(devicetypeService.insertDevicetype(devicetype));
    }

    /**
     * 修改设备类型表
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:edit')")
    @Log(title = "设备类型表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Devicetype devicetype)
    {
        return toAjax(devicetypeService.updateDevicetype(devicetype));
    }

    /**
     * 删除设备类型表
     */
    @PreAuthorize("@ss.hasPermi('device/devicetype:devicetype:remove')")
    @Log(title = "设备类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devicetypeService.deleteDevicetypeByIds(ids));
    }
}
